<?php

function smarty_function_getusername($params, &$smarty) {
    $uid = $params['uid'];

/*
        //Query user layer
        $layerColumn            = $pntables['degis_layer_column'];
        $sql = "
                SELECT
                  $pntables[degis_layer].$layerColumn[id],
                  $pntables[degis_layer].$layerColumn[name],
                  $pntables[degis_layer].$layerColumn[country],
                  $pntables[degis_layer].$layerColumn[url]
                FROM
                  $pntables[users],
                  $pntables[degis_layer]
                WHERE
                    $pntables[users].$userColumn[uid] = $pntables[degis_layer].$layerColumn[uid]
                AND
                    $pntables[degis_layer].$layerColumn[uid] = ".$userArray[0]['uid']."
                ORDER BY $pntables[degis_layer].$layerColumn[id] ASC" ;

          $column = array('id', 'name', 'country', 'url');

          $result = DBUtil::executeSQL($sql);
          $layerArray = DBUtil::marshallObjects ($result, $column);

          $response["uid"]   = $userArray[0]['uid'];
          $response["uname"] = $userArray[0]['uname'];
          $response["email"] = $userArray[0]['email'];
          $response["level"] = $userArray[0]['level'];
*/

    if($uid){
      $pntables = pnDBGetTables();
      $userDataTable  = $pntables['user_data'];
      $userDataColumn = $pntables['user_data_column'];

      $sql = "SELECT $userDataTable.$userDataColumn[uda_value] 
              FROM   $userDataTable 
              WHERE  $userDataTable.$userDataColumn[uda_propid] =1 
              AND    $userDataTable.$userDataColumn[uda_uid] = ".$uid;

      $column = array("username");
      $result = DBUtil::executeSQL($sql);
      $objectArray = DBUtil::marshallObjects ($result, $column);
      if(trim($objectArray['0']['username']) != ""){
        $username = $objectArray['0']['username'];
      }else{
        $pntables = pnDBGetTables();
        $usersTable  = $pntables['users'];
        $usersColumn = $pntables['users_column'];

        $sql = "SELECT $usersTable.$usersColumn[uname] FROM $usersTable WHERE $usersTable.$usersColumn[uid] = ".$uid;
        $column = array("username");
        $result = DBUtil::executeSQL($sql);
        $objectArray = DBUtil::marshallObjects ($result, $column);
        $username = $objectArray['0']['username'];
      }
    }else{
      $username= "-";
    }

    return $username;
}

